"use strict";
var line3DFit_1 = require('./../Service/line3DFit');
var chai = require("chai");
var expect = chai.expect;
describe.only('测试线性回归', function () {
    describe('#二维直线的线性回归', function () {
        it('应该能够正确的解析出直线的参数', function () {
            var line2d = line3DFit_1.Line2d.createLine2d([1, 3], [2, 4]);
            console.log(`\t目标直线的a是${line2d.a},目标直线的b是${line2d.b}`);
            var testXArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
            var testYArray = testXArray.map(function (x) {
                //加个随机数,改造一下y
                var y = line2d.getDependentVar(x) + (Math.random() - 0.5) / 2;
                return y;
            });
            var fitLine2d = line3DFit_1.Line2d.line2dFit(testXArray, testYArray);
            console.log(`\t拟合直线的a是${fitLine2d.a},目标直线的b是${fitLine2d.b}`);
        });
    });
    describe('#三维直线的线性回归', function () {
        it('应该能正确的解析出三维直线的参数', function () {
            var line3d = new line3DFit_1.Line3d([1, 2, 5], [2, 3, 8]);
            var testDist = [-3, -2, -1, 0, 1, 2, 3, 4];
            var ptArray = testDist.map(d => {
                var pt = line3d.getXYZ(d);
                pt = pt.map(v => {
                    return v + (Math.random() / 10 - 0.05) / 2;
                });
                return pt;
            });
            console.log('\t测试使用的点坐标是');
            console.log(ptArray);
            var fitLine = line3DFit_1.Line3d.line3dFit(ptArray);
            var fitPtArray = ptArray.map(function (pt) {
                return [pt[0], fitLine.getY(pt[0]), fitLine.getZ(pt[0])];
            });
            console.log('\t在x坐标相同的情况下,最终拟合直线上的坐标为:');
            console.log(fitPtArray);
        });
    });
});
